package com.shop.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.shop.dao.OrderDetailDao;
import com.shop.entity.OrderDetail;

@Repository
@Transactional
public class OrderDetailDaoImpl extends HibernateTemplate implements OrderDetailDao{

	@Autowired
	private SessionFactory sessionFactory;
	

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public List<OrderDetail> findAllOrder() {
		return (List<OrderDetail>) super.find("from OrderDetail");
	}

	@Override
	public Serializable addOrderDetail(OrderDetail orderDetail) {
		return super.save(orderDetail);
	}

	@Override
	public Serializable deleteOrderDetail(OrderDetail orderDetail) {
		super.delete(orderDetail);
		return null;
	}

	@Override
	public Serializable updateOrderDetail(OrderDetail orderDetail) {
		super.update(orderDetail);
		return null;
	}

	@Override
	public OrderDetail selectByOrderDetailId(OrderDetail orderDetail) {
		String hql = "from Order where eo_id = :eoid ";
		Session session = sessionFactory.openSession();
		Query q = session.createQuery(hql);
		q.setInteger("eoid", orderDetail.getEodId());
		return (OrderDetail) q.uniqueResult();
	}

	
	

}
